<?php
########################################################################################
# Empresa :     Tecnopac Informatica;                                                  #
# Autor:        Deiverson Pacheco;                                                     #
# Data Criação: 10/12/2010;                                                            #
########################################################################################
session_start();
header("Cache-control: private");
include_once("../../includes/session.php");


//Linha para formatação de caracteres com acentuação
header("Content-Type: text/html; charset=ISO-8859-1",true);


//======================================================================================
//==> Include obrigatórias no script
//======================================================================================
include_once('../../includes/classes/class.TemplatePower.php');
include_once('../../includes/classes/class.Conexao.php');
include_once('../../includes/classes/class.Geral.php');

//======================================================================================
//==> Inicializar Classes
//======================================================================================
$not  = new Persist;
$not2 = new Persist;
$data = new getData;
$cor  = new ColorTr;
$util = new Util;
$vld  = new ValidarDados;
$sql  = new SqlInjection;

//======================================================================================
//==> Instanciar TemplatePower para juntar o PHP + HTML
//======================================================================================

//$tpl  = new TemplatePower('../../html/geral/popup_categorias_cadastro_man.html');
//$tpl->prepare();


//======================================================================================
//==> Recebe variaveis de pesquisa
//======================================================================================
$id     = @$_GET['id'];
$evento = @$_GET['evento'];

//======================================================================================
//==> Executa case conforme evento
//======================================================================================

if(isset($evento)){
	switch($evento){
		
		case 'inserir': {
			$id_associado  = @$sql->tratar($_GET['id_associado'],10);
			$id_pess  		= @$sql->tratar($_GET['id_pess'],10);
			
			//captura data e hora atual
			$dt = $data->getDataHoje('-').' '.$data->getHora();
			
			$not->sql = "insert into contatos_associados
						(id_cadastrof, id_cadastroj, data_hora, uid) 
						 values 
						('$id_associado', '$id_pess', '$dt', '$ID_USUARIO')";
			$not->ins();
			
			header("location: popup_contatos_associados.php?id=".$id_pess);
			//echo($id_pess);
		break;
		}
		
		
		case 'excluir': {
			$codigos = explode(";",$id);

			$not2->sql = "Select id_cadastroj from contatos_associados where id_cadastrof = '$codigos[1]'";
			$not2->ler();
			$not2->ini();
			$id_associado = $not2->id_cadastroj;

			for($i=0;count($codigos)>$i;$i++){ 
                $id = $sql->tratar($codigos[$i],10);
				$not->sql = "Delete from contatos_associados where id_cadastrof = '$codigos[$i]'";
				$not->del();
			}
			header("location: popup_contatos_associados.php?id=".$id_associado);

		break;
		}
		
		
		
	}
}


//======================================================================================
//==> Enviar página unificada PHP + HTML
//======================================================================================
$tpl->showUnAssigned( false );  // para debug. na hora de publicar, setar para false
$tpl->printToScreen();
?>